#import "GameObject.h";
#import "Tileset.h"
@implementation GameObject
@synthesize  currentFrame,x,y,set,delegate ;
-(id)initWithDictionary:(NSMutableDictionary*)dic{
		return[self initWithDictionary:dic width:32 height:32];
}
-(id)initWithDictionary:(NSMutableDictionary*)dic width:(int)w  height:(int)h {
	self.x=[[dic objectForKey:@"x"] intValue];
	self.y=[[dic objectForKey:@"y"] intValue];
	self.currentFrame=[[dic objectForKey:@"currentFrame"] intValue];
	[super initWithFrame:CGRectMake(x*w, y*h, w, h)];
	self.backgroundColor = [UIColor blueColor];
	self.center=CGPointMake(x*w, y*h);
	return self;
}
/*-(void)drawRect:(CGRect)rect{
	UIImage* img = [set getImage:currentFrame];
	[img drawInRect:rect];
	
}*/

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	if ([delegate respondsToSelector:@selector(gameObjectTapped:)])
		[delegate gameObjectTapped:self];
}
-(NSMutableDictionary*) toDictionary{
	NSMutableDictionary*dic=[NSMutableDictionary dictionaryWithCapacity:20];
	[dic setValue:[NSNumber numberWithInt:x] forKey:@"x"];
	[dic setValue:[NSNumber numberWithInt:y] forKey:@"y"];
	[dic setValue:[NSNumber numberWithInt:currentFrame] forKey:@"currentFrame"];
	[dic retain];
	return dic;
}

@end